package com.mm.mindmap.domain.es;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mm.mindmap.domain.po.MindMap;
import io.swagger.models.auth.In;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class MindMapDOC {
    private Long id;
    private String title;
    private String nodeList;
    private Double score;
    private Integer like;
    private Integer view;
    private Integer collect;
    @JsonFormat( pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date createTime;



    public String analysisNodeList(){
        StringBuilder ret = new StringBuilder();
        JSONArray jsonArray = new JSONArray(this.nodeList);

        // 遍历JSON数组，取出每个元素的text字段
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject obj = jsonArray.getJSONObject(i);
            String text = obj.getStr("text");
            String topic = obj.getStr("topic");

            ret.append("<"+topic + "> " + text+"\n");
        }
        return ret.toString();
    }
}
